package com.eascs.web.o2o.scheduler.dao;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.eascs.app.dao.JdbcSession;
import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;

@Repository
public class WorkflowDao {
	@Inject
	JdbcSession jdbcSessionForWorkflow;
	@Inject
	JdbcSession jdbcSessionForOracle;

	/**
	 * 统计表中数量
	 * 
	 * @param sql
	 * @return
	 */
	public Integer count(String sql,Object...params ) {

		return this.jdbcSessionForOracle.findInteger(sql, params);

	}

	/**
	 * 分页查询
	 * 
	 * @param sqlPageQuery
	 * @return
	 */
	public <T> PageResult<T> findDataWithPage(SqlPageQuery<T> sqlPageQuery) {
		return this.jdbcSessionForOracle.findDataWithPage(sqlPageQuery);
	}
	
	public <T> PageResult<T> findDataWithPageForService(SqlPageQuery<T> sqlPageQuery) {
		return this.jdbcSessionForWorkflow.findDataWithPage(sqlPageQuery);
	}


	public List<Object[]> findParams(String sql,Object...params ){
		return this.jdbcSessionForWorkflow.findObjectsList(sql, params);
	}

	/**
	 * 保存该表数据
	 */
	//@Transactional(transactionManager = "transactionManagerDbForWorkflow")
	public void saveEntity(Object entity) {
		jdbcSessionForWorkflow.insert(entity);
	}

	/**
	 * 删除数据
	 */
	public void deleteEntity(String delSql) {
		jdbcSessionForWorkflow.execute(delSql);
	}

	/**
	 * @param sql
	 *            保存
	 */
    //@Transactional(transactionManager = "transactionManagerDbForWorkflow")
	public void excuteSql(String sql, Object... params) {

    	jdbcSessionForWorkflow.execute(sql, params);

	}
    
    
    public <T> List<T> findSimpleObjectList(String sql, Class<T> requiredType, Object... params){
		return jdbcSessionForWorkflow.findSimpleObjectList(sql, requiredType, params);
	}
    
	
    public Integer countMysql(String sql,Object... params) {
		return this.jdbcSessionForWorkflow.findInteger(sql, params);

	}
    
    @Transactional(transactionManager = "transactionManagerDbForWorkflow")
	public boolean updateEntity(Object entity) {
		return jdbcSessionForWorkflow.updateById(entity)>0;
	}
}
